package com.zx.oa.controller;

import com.zx.oa.service.student.StudentService;
import com.zx.oa.service.student.StudentServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/delservlet.do")
public class Delservlet extends HttpServlet {

    StudentService studentService=new StudentServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id= Integer.valueOf(request.getParameter("stuNo"));
        String name=request.getParameter("namec");
        String className=request.getParameter("classname");
        String major=request.getParameter("major");
        Integer index= Integer.valueOf(request.getParameter("pageIndex"));
        boolean flag=studentService.delStudent(id);
        if(flag){
            request.setAttribute("namec",name);
            request.setAttribute("classname",className);
            request.setAttribute("major",major);
            request.setAttribute("pageIndex",index);
            request.getRequestDispatcher("chaservlet.do").forward(request,response);
//            response.sendRedirect("chaservlet.do");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
